﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickGraph;

namespace EpidemicSimulator.states
{
    public class SusceptibleState: State
    {
        public override void stateAction(long simTime)
        {
            
        }

        public override void infect(SocialNetworkNode infectingNode, long simTime)
        {
            Random random = new Random();
            double r = random.NextDouble();
            double p = 0;
            foreach (DiseaseModelEdge edge in diseaseModelGraph.OutEdges(stateNode))
            {
                p += edge.transitionProbability;
                if (r <= p && !changingState && edge.condition == node.socialNetwork.AdjacentEdge(infectingNode,0).Condition)
                {
                    int tmp = node.socialNetwork.AdjacentEdge(infectingNode, 0).Condition;
                    State newState = getStateInstance(edge.Target.stateClass);
                    newState.diseaseModelGraph = diseaseModelGraph;
                    newState.stateNode = edge.Target;
                    newState.node = node;
                    newState.maxContacsPerStep = maxContacsPerStep;
                    newState.minContacsPerStep = minContacsPerStep;
                    int delay = random.Next(edge.minTransitionTime, edge.maxTransitionTime);
                    changeState(newState, simTime, delay);
                    return;
                }
            }
        }
    }
}
